package com.zhouyer.study.service.impl.com.zhouyer.study;

import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;

/**
 * 服务启动
 *
 * @author zhouyao
 * @version 1.0
 * @date 2021/11/22 5:16 下午
 */
public class ProviderMain {
    private static final String ZK_PROTOCOL_ADDRESS = "zookeeper://10.211.55.3:2181";

    public static void main(String[] args) throws IOException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
        context.start();
        System.out.println("-----服务提供者启动成功");
        System.in.read();
    }

    @Configuration
    @EnableDubbo(scanBasePackages = "com.zhouyer.study.service.impl")
    @PropertySource(value = "classpath:dubbo-provider.properties")
    static class ProviderConfiguration {
        @Bean
        public RegistryConfig registryConfig() {
            RegistryConfig registryConfig = new RegistryConfig();
            registryConfig.setAddress(ZK_PROTOCOL_ADDRESS);
            return registryConfig;
        }
    }
}
